// Copyright (C) 2025 woodycpp
//
// This work is licensed under the Creative Commons Attribution-ShareAlike 4.0
// International License. To view a copy of this license, visit
// https://creativecommons.org/licenses/by-sa/4.0/
//
// You are free to:
//   * Share — copy and redistribute the material in any medium or format
//   * Adapt — remix, transform, and build upon the material
//
// Under the following terms:
//   * Attribution — You must give appropriate credit, provide a link to the
//   license,
//     and indicate if changes were made. You may do so in any reasonable
//     manner, but not in any way that suggests the licensor endorses you or
//     your use.
//   * ShareAlike — If you remix, transform, or build upon the material, you
//   must
//     distribute your contributions under the same license as the original.
//
// In short: You must credit the original author (woodycpp, 2025) and share any
// derivative works under the same CC-BY-SA-4.0 license.

#include <gtest/gtest.h>

#include "left_rotate.h"

TEST(leftRotateTest, SingleElement_P0) {
    int R[] = {5};
    int n = 1;
    int p = 0;
    leftRotate(R, n, p);
    EXPECT_EQ(R[0], 5);
}

TEST(leftRotateTest, SingleElement_P1) {
    int R[] = {5};
    int n = 1;
    int p = 1;
    leftRotate(R, n, p);
    EXPECT_EQ(R[0], 5);
}

TEST(leftRotateTest, NoRotation_P0) {
    int R[] = {1, 2, 3, 4, 5};
    int n = 5;
    int p = 0;
    leftRotate(R, n, p);
    int expected[] = {1, 2, 3, 4, 5};
    for (int i = 0; i < n; ++i) {
        EXPECT_EQ(R[i], expected[i]);
    }
}

TEST(leftRotateTest, NoRotation_PN) {
    int R[] = {1, 2, 3, 4, 5};
    int n = 5;
    int p = 5;
    leftRotate(R, n, p);
    int expected[] = {1, 2, 3, 4, 5};
    for (int i = 0; i < n; ++i) {
        EXPECT_EQ(R[i], expected[i]);
    }
}

TEST(leftRotateTest, NormalRotation_N5_P2) {
    int R[] = {1, 2, 3, 4, 5};
    int n = 5;
    int p = 2;
    leftRotate(R, n, p);
    int expected[] = {3, 4, 5, 1, 2};
    for (int i = 0; i < n; ++i) {
        EXPECT_EQ(R[i], expected[i]);
    }
}

TEST(leftRotateTest, NormalRotation_N5_P3) {
    int R[] = {1, 2, 3, 4, 5};
    int n = 5;
    int p = 3;
    leftRotate(R, n, p);
    int expected[] = {4, 5, 1, 2, 3};
    for (int i = 0; i < n; ++i) {
        EXPECT_EQ(R[i], expected[i]);
    }
}